<script>

import * as echarts from 'echarts';
// import $ from 'jquery'
export default {
  name: 'VisualizationFour',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data4', {}).then(res => {
        if (res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          for (let i = 0; i < 11; i++) {
            if( res.data.data[i].param1 !== "") {
              data1.push(
                  res.data.data[i].param1
              );
              data2.push(
                  res.data.data[i].param2
              );
            }
          }
          console.log(data1);
          console.log(data2);
          this.init(data1, data2)
        }
      }).catch(error => {
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2) {
      var chartDom = document.getElementById('main4');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: [
          {
            text: '热销品牌Top10'
          }
        ],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          },
          valueFormatter: (value) => value + '元' //改变显示文字
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          name: '销售额',
          nameLocation: 'start',
          type: 'value',
          splitLine: { show: false },
          nameTextStyle: {
            color: 'black'
          },
          axisLine: {
            show: true
          },
          axisTick: {
            show: true //刻度线
          },
          splitNumber: 10,
          max: 15800
        },
        yAxis: {
          name: "品牌",
          type: 'category',
          data: data1,
          axisLabel: {
            color: 'black'
          },
          axisLine: {
            show: false //隐藏y轴
          },
          axisTick: {
            show: false //刻度线
          }
        },
        series: [
          {
            type: 'bar',
            data: data2,
            itemStyle: {
              normal: {
                barBorderRadius: 31,// 让柱形上下变成圆角
                color: function (params) {
                  var colorList = ["#347caf", "#54bcbd", "#e99d42", "#4095e5", "#54bcbd", "#e99d42", "#4095e5", "#ff5b5b","#e99d42", "#4095e5", "#ff5b5b"];
                  return colorList[params.dataIndex]
                },
                label: {
                  formatter: "{c}" + "元", //显示柱子上的文字
                  show: true,
                  position: [20, 10],
                  textStyle: {
                    fontWeight: "bolder",
                    fontSize: "16",
                    color: "black"
                  }
                }
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    }
  }

}
</script>

<template>
  <div id="main4"></div>
</template>

<style scoped>
#main4 {
  width: 100%;
  height: 100%;
}
</style>